<?php


namespace app\api\controller\PayExchange;


use app\common\Log;
use app\common\OutPay\SafePay;
use think\facade\Validate;

/**
 * 代付 - 异步回调
 * Class NotifyController
 * @package App\Http\Controllers
 */
class OutPayNotify
{
    /**
     * @return string
     */
    public function safePay()
    {
        $params = \request()->all();
        $validator = Validate::make($params, [
            'mer_no' => 'required',
            'order_no' => 'required',
            'order_amount' => 'required',
            'order_realityamount' => 'required',
            'currency' => 'required',
            'sys_no'=>'required',
            'result'=>'required',
            'sign' => 'required',
        ]);


        if ($validator->fails()) {
//            \App\Common\Log::write('safepay代付回调参数：'.json_encode($params),'outPay','outPay');
            return 'err';
        }
        $pay = new SafePay(config('outpay.safe_pay'));
        $ret = $pay->notify($params);
        Log::write('safepay代付回调本地响应：'. $pay->getErr() ,'outPay','outPay');
            return 'ok';
    }


}